import 'package:aidw_ui/res/assets_res.dart';
import 'package:aidw_ui/res/i_font_res.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../values/app_colors.dart';
import '../../values/app_radii.dart';
import 'logic.dart';

class WelcomePage extends StatelessWidget {
  final logic = Get.find<WelcomeLogic>();
  final state = Get.find<WelcomeLogic>().state;

  /// 页头标题
  Widget _buildPageHeadTitle() {
    return Container(
      margin: EdgeInsets.only(top: (60 + 44.0).h), // 顶部系统栏 44px
      child: Text(
        "欢迎",
        textAlign: TextAlign.center,
        style: TextStyle(
          color: AppColors.primaryText,
          fontFamily: FontRes.MONTSERRAT_SEMIBOLD,
          fontWeight: FontWeight.w600,
          fontSize: 24.sp,
          height: 1,
        ),
      ),
    );
  }

  /// 页头说明
  Widget _buildPageHeaderDetail() {
    return Container(
      width: 242.w,
      height: 70.h,
      margin: EdgeInsets.only(top: 14.h),
      child: Text(
        "本地调试，远程查看，请联系供应商，申请用户名和密码",
        textAlign: TextAlign.center,
        style: TextStyle(
          color: AppColors.primaryText,
          fontFamily: FontRes.AVENIR,
          fontWeight: FontWeight.normal,
          fontSize: 16.sp,
          height: 1.3,
        ),
      ),
    );
  }

  /// 特性说明
  /// 宽度 80 + 20 + 195 = 295
  Widget _buildFeatureItem(String imageName, String intro, double marginTop) {
    return Container(
      width: 295.w,
      height: 80.h,
      margin: EdgeInsets.only(top: marginTop.h),
      child: Row(
        children: [
          Container(
            width: 80.w,
            height: 80.w,
            child: Image.asset(
              imageName,
              fit: BoxFit.none,
            ),
          ),
          Spacer(),
          Container(
            width: 195.w,
            child: Text(
              intro,
              textAlign: TextAlign.left,
              style: TextStyle(
                color: AppColors.primaryText,
                fontFamily: FontRes.AVENIR,
                fontWeight: FontWeight.normal,
                fontSize: 16.sp,
              ),
            ),
          ),
        ],
      ),
    );
  }

  /// 开始按钮
  Widget _buildStartButton(BuildContext context) {
    return Container(
      width: 295.w,
      height: 44.h,
      margin: EdgeInsets.only(bottom: 24.h),
      child: TextButton(
        style: ButtonStyle(
          textStyle: MaterialStateProperty.all(TextStyle(
            fontSize: 16.sp,
          )),
          foregroundColor: MaterialStateProperty.resolveWith(
                (states) {
              if (states.contains(MaterialState.focused) &&
                  !states.contains(MaterialState.pressed)) {
                return Colors.blue;
              } else if (states.contains(MaterialState.pressed)) {
                return Colors.deepPurple;
              }
              return AppColors.primaryElementText;
            },
          ),
          backgroundColor: MaterialStateProperty.resolveWith((states) {
            if (states.contains(MaterialState.pressed)) {
              return Colors.blue[200];
            }
            return AppColors.primaryElement;
          }),
          shape: MaterialStateProperty.all(RoundedRectangleBorder(
            borderRadius: AppRadii.k6pxRadius,
          )),
        ),
        child: Text("点击进入"),
        onPressed: logic.goLogin,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: <Widget>[
            ScaleTransition(
              scale: Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
                parent: logic.animationController,
                curve: Interval(0.0, 0.3, curve: Curves.fastOutSlowIn),
              )),
              child: _buildPageHeadTitle()
            ),
            ScaleTransition(
                scale: Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
                  parent: logic.animationController,
                  curve: Interval(0.0, 0.3, curve: Curves.fastOutSlowIn),
                )),
                child: _buildPageHeaderDetail()
            ),
            ScaleTransition(
                scale: Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
                  parent: logic.animationController,
                  curve: Interval(0.3, 0.6, curve: Curves.fastOutSlowIn),
                )),
                child: _buildFeatureItem(
                  AssetsRes.WELCOME_FEATURE_1,
                  "Sector news never shares your personal data with advertisers or publishers",
                  86,
                )
            ),
            ScaleTransition(
                scale: Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
                  parent: logic.animationController,
                  curve: Interval(0.3, 0.6, curve: Curves.fastOutSlowIn),
                )),
                child: _buildFeatureItem(
                  AssetsRes.WELCOME_FEATURE_2,
                  "Sector news never shares your personal data with advertisers or publishers",
                  40,
                ),
            ),
            ScaleTransition(
                scale: Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
                  parent: logic.animationController,
                  curve: Interval(0.3, 0.6, curve: Curves.fastOutSlowIn),
                )),
                child: _buildFeatureItem(
                  AssetsRes.WELCOME_FEATURE_3,
                  "You can get Premium to unlock hundreds of publications",
                  40,
                )
            ),
            Spacer(),
            ScaleTransition(
                scale: Tween<double>(begin: 0.6, end: 1).animate(CurvedAnimation(
                  parent: logic.animationController,
                  curve: Interval(0.8, 1, curve: Curves.fastOutSlowIn),
                )),
                child: _buildStartButton(context)
            ),
          ],
        ),
      ),
    );
  }
}
